package com.atguigu.eduservice.controller;

import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 讲师控制器
 * @author daygods
 * @since 2025-07-12
 */
@RestController
@RequestMapping("/api/edu/teacher")
@CrossOrigin
public class EduTeacherController {

    @Autowired
    private EduTeacherService teacherService;

    /**
     * 查询所有讲师
     */
    @GetMapping("/findAll")
    public List<EduTeacher> findAllTeacher() {
        List<EduTeacher> list = teacherService.list(null);
        return list;
    }

    /**
     * 逻辑删除讲师
     */
    @DeleteMapping("/{id}")
    public boolean removeTeacher(@PathVariable String id) {
        boolean flag = teacherService.removeById(id);
        return flag;
    }

    /**
     * 分页查询讲师
     */
    @GetMapping("/pageTeacher/{current}/{limit}")
    public Page<EduTeacher> pageListTeacher(@PathVariable long current,
                                           @PathVariable long limit) {
        Page<EduTeacher> pageTeacher = new Page<>(current, limit);
        teacherService.page(pageTeacher, null);
        return pageTeacher;
    }

    /**
     * 添加讲师
     */
    @PostMapping("/addTeacher")
    public boolean addTeacher(@RequestBody EduTeacher eduTeacher) {
        boolean save = teacherService.save(eduTeacher);
        return save;
    }

    /**
     * 根据讲师id进行查询
     */
    @GetMapping("/getTeacher/{id}")
    public EduTeacher getTeacher(@PathVariable String id) {
        EduTeacher eduTeacher = teacherService.getById(id);
        return eduTeacher;
    }

    /**
     * 讲师修改功能
     */
    @PostMapping("/updateTeacher")
    public boolean updateTeacher(@RequestBody EduTeacher eduTeacher) {
        boolean flag = teacherService.updateById(eduTeacher);
        return flag;
    }
}